package com.thzy.bbs.dao;

import com.thzy.bbs.entity.MessageNumber;

import org.xutils.DbManager;
import org.xutils.ex.DbException;

import java.util.List;

/**
 * 消息数量操作
 *
 * @author
 * @date 2017/1/22 10:21
 */

public class MessageNumberDao {
    private DbManager dbManager = DbInit.init();
    public static boolean isHaveNew = false;


    public static boolean isHaveNew() {
        return isHaveNew;
    }

    public static void setIsHaveNew(boolean isHaveNew) {
        MessageNumberDao.isHaveNew = isHaveNew;
    }

    public MessageNumber findById(Integer id) {
        try {
            return dbManager.findById(MessageNumber.class, id);
        } catch (DbException e) {
            e.printStackTrace();
        }
        return null;
    }

    public void saveOrUpdate(MessageNumber messageNumber) {
        try {
            dbManager.saveOrUpdate(messageNumber);
        } catch (DbException e) {
            e.printStackTrace();
        }
    }

    public List<MessageNumber> findAll() {
        try {
            return dbManager.findAll(MessageNumber.class);
        } catch (DbException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 修改数据
     *
     * @param columnNames 修改字段名
     */
    public void update(String... columnNames) {
        try {
            dbManager.update(MessageNumber.class, columnNames);
        } catch (DbException e) {
            e.printStackTrace();
        }
    }
}
